/**
 * 
 */
package ua.kpi.javatrainee6.model.curriculum;

import java.util.Arrays;
import java.util.Iterator;

import ua.kpi.javatrainee6.model.people.*;

/** 
 * Encapsulating logic for work with array of subjects
 */
public class Subjects implements Iterable<Subject>{
	
	private static final int SUBJECTS_NUMBER = 5;
	private Subject[] subjects;
	
	/**
	 * creating subjects, subjects instances are now like {subject1, ..}, {subject2, ..}
	 * All subjects are taught by FIRST PROFESSOR, real data will change situation
	 */
	public Subjects(Professors professors) {
		subjects = new Subject[SUBJECTS_NUMBER];
		for (int i = 0; i < SUBJECTS_NUMBER; i++) {
			subjects[i] = new Subject(professors.get(0));
		}
	}
	
	private Subjects(Subject[] subjects) {
		this.subjects = subjects;
	}
	
	public Iterator<Subject> iterator() {
		return Arrays.asList(subjects).iterator();
	}
	
	public Subject get(int index) {
		return subjects[index];
	}
	
	public Subjects copy() {
		return new Subjects(subjects.clone());
	}
	
	public int size() {
		return subjects.length;
	}
	
	public int getIndex(Subject subject) {
		for (int index = 0; index < subjects.length; index++) {
			if (subjects[index].equals(subject)) {
				return index;
			}
		}
		throw new RuntimeException(String.format("%s not found", subject));
	}
}
